package com.jiyun.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @projectName: 2210A-project1
 * @package: com.jiyun.controller
 * @className: KafkaPrv
 * @author: 耿嘉军
 * @date: 2023/9/9 16:21
 * @version: 1.0
 */
@RestController
@RequestMapping("kafka")
@Slf4j
public class KafkaPrv {

    @Autowired
    private KafkaTemplate kafkaTemplate;

    @RequestMapping("/hello")
    public String hello(){
        try {
            //第一个参数：topics
            //第二个参数：消息内容
            log.info("进入kafka");
            kafkaTemplate.send("kafka-hello","积云程序员");
            log.info("发送成功");
            return "ok";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }
}
